﻿namespace KeRui.Common
{
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class XmlWrite
    {
        [STAThread]
        public static int Main(string[] args)
        {
            XMLComponent component = new XmlWrite().Setup();
            Console.WriteLine(component.FileEncode);
            Console.WriteLine(component.WriteFile());
            if (component.WriteStringBuilder() != null)
            {
                Console.WriteLine(component.WriteStringBuilder().ToString());
            }
            return 0;
        }

        private XMLComponent Setup()
        {
            ConcreteComponent xc = new ConcreteComponent("This is the RSS component");
            DataSet dataSet = new DataSet();
            SqlConnection selectConnection = new SqlConnection("server=192.168.2.198;database=RSS;uid=sa;pwd=;");
            new SqlDataAdapter("Select  *  From Rss_ChannelItem", selectConnection).Fill(dataSet);
            dataSet.Tables[0].TableName = "xml";
            xc.SourceDataTable = dataSet.Tables[0];
            xc.FileName = "test.xml";
            xc.FileOutPath = @"c:\";
            XMLDecorator decorator = new XMLDecorator("This is a decorator for the component");
            decorator.SetXMLComponent(xc);
            return decorator;
        }
    }
}

